package com.example.clienta.controller;

import org.springframework.boot.web.servlet.server.Session;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Enumeration;

@Controller
public class PageController {
    @RequestMapping("/")
    public String indexPage(){
        return "index";
    }

    @RequestMapping("/securedPage")
    public String securedPage() {
        return "securedPage";
    }

    @RequestMapping("/test")
    @PreAuthorize("hasRole('admin')")
    @ResponseBody
    public String test(){
        return "这是client-a上的test接口";
    }

    @RequestMapping("/abc")
    @ResponseBody
    public String abc(HttpServletRequest request){
        Enumeration<String> strings=request.getHeaderNames();
        while (strings.hasMoreElements()){
            String name=strings.nextElement();
            System.out.println(name+":"+request.getHeader(name));
        }
        System.out.println(request.getSession().getId());
        return strings.toString();
    }
}
